package edu.gatech.startrader;

import edu.gatech.startrader.player.Player;
import edu.gatech.startrader.universe.Planet;
import edu.gatech.startrader.universe.Universe;

/**
 * Game Class
 * Handles all objects used in the game.
 * Singleton
 * @author Team Bamf (Team 30)
 * @version 1.0
 */
public class Game {
	
	/**
	 * Enumerated type: Determinant of how hard the game is to play
	 */
	public enum Difficulty {
		/**
		 * Beginner Difficulty:
		 */
		BEGINNER, 
		
		/**
		 * Easy Difficulty:
		 */
		EASY, 
		
		/**
		 * Normal Difficulty:
		 */
		NORMAL, 
		
		/**
		 * Hard Difficulty:
		 */
		HARD, 
		
		/**
		 * Impossible Difficulty:
		 */
		IMPOSSIBLE
	}
	
	/**
	 * The current Game's difficulty
	 */
	private  Difficulty difficulty;
	
	/**
	 * Player object handling the information pertaining to the Player
	 */
	private final Player player;
	
	/**
	 * Object handling the information pertaining to the Universe the Game is set in
	 */
	private final Universe universe;
	
	/**
	 * private Game Constructor
	 * @param universe the Universe that will be created
	 * @param playerInfo the Player's information
	 * @param difficulty the difficulty of the game
	 */
	private Game(Universe universe, Player playerInfo, Difficulty difficulty) {
		this.universe = universe;
		this.difficulty = difficulty;
		player = playerInfo;
		universe.recalculateTravelablePlanets(player.getShip().getFuel());
	}
	
	/**
	 * getDifficulty method
	 * This method gets the difficulty. 
	 * @return difficulty
	 */
	public Difficulty getDifficulty() {
		return difficulty;
	}
	
	/**
	 * setDifficulty Method
	 * This method sets the difficulty of the game.
	 * @param t the difficulty of the game
	 */
	public  void setDiffculty(Difficulty t) {
		difficulty = t;
	}
	
	/**
	 * getPlayer method
	 * Gets the Player object.
	 * @return player 
	 */
	public Player getPlayer() {
		return player;
	}
	
	/**
	 * getCurrentPlanet method
	 * Gets the current Planet that the Player is on.
	 * @return the current Planet the Player is on
	 */
	public Planet getCurrentPlanet() {
		return universe.getCurrentPlanet();
	}
	
	/**
	 * getUniverse method
	 * Gets the Universe object
	 * @return the current Universe object
	 */
	public Universe getUniverse() {
		return universe;
	}
	
	/**
	 * startNewGame method
	 * This method starts a brand new game to Play.
	 * @param playerInfo the Player object's information
	 * @param difficulty the difficulty of the game
	 * @return the Game object of the game that was just started
	 */
	public static Game startNewGame(Player playerInfo, Difficulty difficulty) {
		if(playerInfo == null) {
			throw new IllegalArgumentException("Player cannot be null");
		}
		final Universe universe = Universe.generateUniverse();
		return new Game(universe, playerInfo, difficulty);
	}
	
	/**
	 * Returns the Game object as a String
	 * @return the object as a String
	 */
	@Override
	public String toString() {
		return universe.toString() + player.toString();
	}
}
